package com.xk.controller;

import com.xk.mapper.TeacherMapper;
import com.xk.pojo.Page;
import com.xk.pojo.Teacher;
import com.xk.service.TeacherService;
import com.xk.utils.MyBatisUtils;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

//    http://localhost:8080/teacher/getAllteacher
    @RequestMapping("/getAllteacher")
    @ResponseBody
    public List<Teacher> getAllteacher(){
        List<Teacher> allTeachers = teacherService.getAllTeachers();
        return allTeachers;
    }
    @GetMapping("/gototeacherlist")
    public String gototeacherlist(){

        return "redirect:/teacherlist.jsp";
    }

    @RequestMapping("/deleteTeacherbyId")
    @ResponseBody
    public String deleteTeacherbyId(Integer teacherID){
        System.out.println("delete");
        teacherService.deleteTeacherById(teacherID);
        return "aa";
    }

    @RequestMapping("/updateTeacherById")
    public String updateTeacherById(Teacher teacher){
        teacherService.updateTeacherById(teacher);
        return "redirect:/teacherlist.jsp";
    }
    @RequestMapping("/addTeacher")
    @ResponseBody
    public String addTeacher(Teacher teacher){
        String msg = teacherService.addTeacher(teacher);
        return msg;
    }
    @RequestMapping("/getTeacherListByPage")
    @ResponseBody
    public Page<Teacher> getTeacherListByPage(int pageNumber, int pageSize,String search ){
        System.out.println("controller"+search);
        Page<Teacher> page = teacherService.getTeacherListByPage(pageNumber, pageSize,search);
        return page;
    }


}
